export default {
    state: {
        index: {
            tag: 1,
            isCollapse: true, //默认不塌陷

        },
        menu: [],
        token: null,
    },
    getters: {
        _isCollapse(state) {
            return state.index.isCollapse
        },
        _tag(state) {
            return state.index.tag
        },
        _menu(state) {
            return state.menu
        },
        GET_TOKEN(state) {
            return state.token
        }
    },
    mutations: {
        SET_TOKEN(state, val) {
            state.token = val
            //在保存token到vuex时就订阅一个未来事件 卸载页面时将token保存到本地
            window.addEventListener('beforeunload', function (evt) {
                evt.preventDefault()
                localStorage.setItem('token', state.token)
                localStorage.setItem('state', JSON.stringify(state))
            })
            localStorage.removeItem('token')
            localStorage.removeItem('state')
        },
        _updateIndexTag(state, tag) {
            state.index.tag = tag
        },
        _setIsCollapse(state, isCollapse) {
            state.index.isCollapse = isCollapse
        },
        _setMenu(state, menu) {
            state.menu = menu
        },
        removeToken(state) {
            state.token = null
        }
    },
}
